/*
 * Copyright (C) 2012 Santiago Valdarrama
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.yuanmei.stockeyes.model;

import android.content.Context;
import com.yuanmei.stockeyes.R;
import com.yuanmei.stockeyes.model.Stock;
import com.yuanmei.stockeyes.model.PolicyBase;

public class OverPolicy extends PolicyBase {
    private Context mContext;
    private int     mCalDays;
    
    public OverPolicy(Context context) {
        mContext = context;
        mCalDays = 3;
    }
    public String  matchResults(Stock stock) {
        Stock.StockPrices warnPrice = stock.getPricesOfLastNDays(mCalDays);
        String warnMessage = null;

        if (stock.getPrice() > warnPrice.mHigh) {
            warnMessage = String.format("%s(%.2f)", stock.getName(), stock.getPrice())  +
                    String.format(mContext.getResources().getString(R.string.overpolicy_up_high_format), 
                     mCalDays, warnPrice.mHigh);
        } else if (stock.getPrice() < warnPrice.mLow ) {
            warnMessage = String.format("%s(%.2f)", stock.getName(), stock.getPrice())  +
                    String.format(mContext.getResources().getString(R.string.overpolicy_under_low_format), 
                     mCalDays, warnPrice.mLow); 
        } 
         
        /* // for debug
        else {
            warnMessage = String.format("%sDBG(%.2f)", stock.getName(), stock.getPrice())  +
                    String.format(mContext.getResources().getString(R.string.overpolicy_up_high_format), 
                     mCalDays, warnPrice.mHigh);
            
        }*/
            
        return warnMessage;
    }
}
